{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcfbase.css?v={$version}"/>
<script src="{__PUBLIC_PATH}/common/js/jquery.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<style>
@media screen and (max-width:800px){
.layui-layer.layui-layer-page{width:100%!important;overflow:hidden!important;left:0!important;}
.layui-layer-title{width:100%!important;box-sizing:border-box;}
.layui-layer-content{width:100%!important;}
}
</style>
<div class="layui-fluid" style="padding-bottom:83px;border:0;" id="LAY-component-layer-list">
<div class="layui-card">
<div class="layui-card-body table-tool-mini">
<div class="layui-form toolbar">
<div class="layui-form-item">
    <div class="layui-inline">
        <button data-type="batch_del" data-url="{:url('/guestbook/condel')}" class="layui-btn layui-btn-danger icon-btn"><i class="layui-icon"></i> 批量删除</button>
    </div>
</div>
</div>
<table class="layui-table" id="tableUser" lay-filter="tableUser"></table>
</div>
<div class="submit-info text-center">
    <button class="layui-btn" type="button" ew-event="closeDialog">返回</button>
</div>
<div class="pcfclear"></div>
</div>
</div>
<script type="text/html" id="tableState">
    <a class="layui-btn layui-btn-primary layui-btn-xs" data-type="edit" data-id="{{d.list_id}}">详细内容</a>
</script>
<script type="text/html" id="tableState1">
<input type="checkbox" name="is_read" data-id="{{d.list_id}}" value="{{d.is_read}}" lay-filter="is_read" lay-skin="switch" lay-text="未读|已读" {{d.is_read == 1 ? '':'checked'}}>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form', 'table'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var form_id = '{$form_id}';
        // 渲染表格
        var insTb = table.render({
            elem: '#tableUser',
            url: "{:url('/guestbook/bookcontent')}?id="+form_id,
            page: true,
            toolbar: true,
            cellMinWidth: 100,
            cols: [[
                {type:'checkbox'},
                {field:'list_id',title:'ID',align: 'center',width:60},
                {field: 'city', title: '提交来源',align: 'center'},
                {field: 'ip', title: 'IP',align: 'center'},
                {field: 'formname', title: '表单类型',align: 'center'},
                {field: 'add_time', title: '提交时间',width: 200,align: 'center'},
                {toolbar: '#tableState1', title: '状态',width: 150, align: 'center'},
                {toolbar: '#tableState', title: '操作', width: 150,align:'center', }
            ]]
        });
        //开启关闭
        form.on('switch(is_read)', function(){
            if ($(this).val() == 0){
                $(this).val(1);
            }else{
                $(this).val(0);
            }
            var dataid = $(this).attr('data-id');
            var pcfurl = '{:url("/index/changeTableVal")}';
            changeTableVal('guestbook_list','list_id',dataid,'is_read',this,pcfurl);
        });
        $(document).on("click","#LAY-component-layer-list .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });
        //触发事件
        var active = {
            edit: function(){
                var obj = this;
                var id = $(obj).attr('data-id');
                layer.open({
                    type: 2,
                    title: '提交内容', 
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "{:url('/guestbook/conedit')}?id="+id
                });
            },
            batch_del: function(){
                var checkRows = table.checkStatus('tableUser');
                if (checkRows.data.length === 0) {
                    layer.msg('请选择要删除的数据', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.list_id;
                });
                batch_del(this, ids);
            }
        }

    });
</script>
</body>
</html>